﻿/********************************************************************************************************************
* Author:	Christos Polydorou																						*
* Email:	std04237@di.uoa.gr																						*
* Purpose:	This script is used in order to create the stored procedure "usp_searchcategories" that searches for	*
*			categories.																								*
********************************************************************************************************************/

CREATE PROCEDURE [dbo].[usp_searchCategories]
	@userid bigint,
	@categoryname nvarchar(50)
AS
	DECLARE @categoryids table ( catid bigint )

	INSERT INTO @categoryids
	EXEC usp_getcategorieswithaccess @usrid = @userid

	SELECT Categories.ID, Categories.Name, Categories.Owner, Categories.IsPrivate, Categories.DateCreated
	FROM categories, @categoryids
	WHERE Categories.ID = catid and Categories.Name like @categoryname
RETURN 0